import React, { useEffect } from 'react'
import * as echarts from 'echarts';

export default function index({id, chartDataList}) {
  useEffect(() => {
    const dom = document.getElementById(`${id}`);
    const chart = echarts.init(dom);
    const option = {
      tooltip: {
        trigger: 'item'
      },
      legend: {
        bottom: '15%',
        left: 'center',
        itemGap: 10, // 减小图例项之间的间距
        itemWidth: 10, // 减小图例框的宽度
        itemHeight: 10, // 减小图例框的高度
        textStyle: {
          fontSize: 12 // 减小字体大小
        }
      },
      series: [
        {
          name: '房屋类别统计',
          type: 'pie',
          radius: ['40%', '70%'],
          center: ['50%', '38%'],
          avoidLabelOverlap: false,
          label: {
            show: true,
            position: 'center',
            formatter: '{b}:{d}%'
          },
          emphasis: {
            label: {
              show: true,
              fontSize: 10,
              fontWeight: 'bold'
            }
          },
          labelLine: {
            show: true
          },
          data: chartDataList[id]
        }
      ]
    };
    option && chart.setOption(option);
    return () => {
      chart.dispose()
    }
  }, [chartDataList])
  return (
    <div style={{height: '100%'}} id={id}></div>
  )
}
